package com.test01_程序基础;

import org.junit.Test;

/**
 * 循环结构
 */
public class YootkDemo_05 {

    @Test
    public void test1() {
        int sum = 0;
        int num = 1;
        while (num <= 100) {
            sum += num;
            num++;
        }
        System.out.println("数字累加结果：" + sum);
    }

    @Test
    public void test2() {
        int sum = 0;
        int num = 1;
        do {
            sum += num;
            num++;
        } while (num <= 100);
        System.out.println("数字累加结果：" + sum);
    }

    @Test
    public void test3() {
        int sum = 0;
        for (int num = 1; num <= 100; num++) {
            sum += num;
        }
        System.out.println("数字累加结果：" + sum);
    }

    @Test
    public void test4() {
        int sum = 0;
        int num = 1;
        for (; num <= 100; ) {
            sum += num;
            num++;
        }
        System.out.println("数字累加结果：" + sum);
    }

    /**
     * 九九乘法表
     */
    @Test
    public void test5() {
        for (int x = 1; x <= 9; x++) {
            for (int y = 1; y <= x; y++) {
                System.out.printf("%d*%d=%d\t", y, x, (x * y));
            }
            System.out.println();
        }
    }

    /**
     * 跳出外层循环
     */
    @Test
    public void test6() {
        point: for (int x = 0; x < 3; x++) {
            for (int y = 0; y < 3; y++) {
                if (x == y) {
                    continue point;
                    // break point;
                }
                System.out.println("x=" + x + "、y=" + y);
            }
        }
    }
}
